perm filename HALIO.PLT[HAL,HE] blob sn#120136 filedate 1974-09-18 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.SBTTL	TTY output routines
C00005 00003	.SBTTL Useful macros for use of I/O routines
C00007 ENDMK
C⊗;
.SBTTL	TTY output routines
;  Modified 5-Sep-74 by RF.  Originally written by KKP.

;	Output a string, ending with a zero character. Pointer to start
;	of string in R0.  Called in "simple" style.

.EVEN
TYPSTR:	MOV R0,R1	;R1 ← LOC[STRING]
	MOVB (R1)+,R0	;R0 ← first byte of string
TSLOOP:	JSR PC,TYPCHR	;Type this one character
	MOVB (R1)+,R0	;R0 ← Next byte of string
	BNE TSLOOP	;If more to come, repeat.
	RTS PC		;Done


; Routines to output numbers.  Argument in R0.
; TYPDEC outputs in base 10, and TYPOCT in base 8.
; Both use TYPDIG as a subroutine, putting the digit
;	in R0.
; TYPCHR is a general purpose character output routine.

.EVEN
TYPDEC:	MOV #12,RADIX	;To output in base 10
	BR TYPDIG	;Go type it.
TYPOCT:	MOV #8,RADIX	;To output in base 8.
	BR TYPDIG	;Go type it.
TYPDIG:	MOV R0,R1	;Need dividend in R1, with R0 clear.
	CLR R0		;Clear upper half of dividend.
	DIV (PC)+,R0	;Divide argument in R0, R1 by radix.
RADIX:	12		;Starts out in decimal.
	BEQ TYPOUT	;If quotient zero, then can print.
	MOV R1,-(SP)	;Else stack quotient
	JSR PC,TYPDIG	;Recursive call.
	MOV (SP)+,R1	;Unstack last quotient
TYPOUT:	ADD #'0,R1	;Form TTY code for digit
	MOV R1,R0	;Need argument for TYPCHR in R0.
TYPCHR:	TSTB KBOS	;Is TTY available?
	BPL TYPCHR	;No.  Busy wait for it.
	MOVB R0,KBOR	;Yes.  Output a byte to it.
	CMP #12,R0	;Was it a line feed?
	BNE TYPRET	;If not that code, then done.
	CLR R0		;Otherwise, output 3 nulls.
	JSR PC,TYPCHR	;
	JSR PC,TYPCHR	;
	JSR PC,TYPCHR	;
TYPRET:	RTS PC		;Return.


.SBTTL Useful macros for use of I/O routines

       .MACRO OUTSTR B	;Type string starting at B.
	MOV R0,-(SP)	;Save R0.  Who knows what was happening in it?
	MOV R1,-(SP)	;Save R1.
	MOV #B,R0	;Load up the string to be output
	JSR PC,TYPSTR	;Call the string output utility routine.
	MOV (SP)+,R1	;Restore R1.
	MOV (SP)+,R0	;Restore R0.
       .ENDM

       .MACRO ASCIE STR
       .ASCIZ STR
       .EVEN
       .ENDM

       .MACRO	CRLF
	OUTSTR CRLFX	;Carriage return, line feed.
       .ENDM

CRLFX: .ASCIZ /
/

RUGMES:	ASCIE </π
--YOU'RE UNDER THE RUG
π/>

       .MACRO HALERR MES	;Bad error.  Type message, call RUG.
	MOV R0,-(SP)	;Save R0.
	MOV R1,-(SP)	;Save R1.
	MOV #CRLFX,R0	;Move to new line
	JSR PC,TYPSTR	;
	MOV #MES,R0	;Type out message
	JSR PC,TYPSTR	;
	MOV #RUGMES,R0	;Type out RUGMES
	JSR PC,TYPSTR	;
	MOV (SP)+,R1	;Restore R1.
	MOV (SP)+,R0	;Restore R2.
	JMP RUG		;Go directly to RUG.
	BR .-4		;In case we return.
       .ENDM

       .MACRO TTYIN B	;To read in a word.
	TSTB KBIS	;Is keyboard ready?
	BEQ .-4		;No.  Busy wait.
	MOV KBIR,B	;Yes.  Read a word.
	BIC #200,B	;Mask off a bit.
       .ENDM